package com.zephyr.vchcenter.pbcFile.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.zephyr.vchcenter.bean.PbcData;
import com.zephyr.vchcenter.bean.PbcOriginalData;

public class BeanOperateUtil {
	public static void beanCopy(Object beanSrc, Object beanTar) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
		Class clazzSrc = beanSrc.getClass();
		Class clazzTar = beanTar.getClass();
		Method[] methodsSrc = clazzSrc.getDeclaredMethods();
		Method[] methodsTar = clazzTar.getDeclaredMethods();
		for (Method methodSrc : methodsSrc) {
			if (methodSrc.getName().substring(0, 3).equals("get")) {
				for (Method methodTar : methodsTar) {
					if (methodTar.getName().substring(0, 3).equals("set")&&methodTar.getName().substring(3).equals(methodSrc.getName().substring(3))) {
						methodTar.invoke(beanTar, methodSrc.invoke(beanSrc)); 
					    System.out.println(methodTar.getName());
					}
				}
			}
		}
	}
	public static void main(String[] args) {
		PbcOriginalData pbcOriginalData=new PbcOriginalData();
		PbcData pbcData=new PbcData();
		pbcOriginalData.setAccno("123123");
		pbcOriginalData.setAmount("11111");
		try {
			BeanOperateUtil.beanCopy(pbcOriginalData, pbcData);
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(pbcData.toString());	
	}
}
